﻿//===============================================================================
// La Pomme d'Or Krystal Application
// Windows Presentation Foundation Composite Application 
//===============================================================================
// Copyright (c) Jérôme Piquot.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;

namespace PJ.Data
{
    /// <summary>
    /// Saves and retreive <see cref="IEntityData"/> instance to/from cache
    /// </summary>
    /// <remarks>
    /// The object will be cached using <see cref="IEntityData"/> concrete type class name and Id property as cache key. So the <see cref="IEntityData"/> Id property must be unique for each concrete class type.
    /// </remarks>
    /// <example>
    /// Add/Find
    /// <code>
    ///     IEntityData data = MyService.GetEntity();
    ///     IEntityDataCache cache = CacheFactory.GetCache();
    ///     
    ///     cache.Add(data);
    ///     IEntityData cacheData = cache.FindById(data.GetType().Name, data.Id);
    ///     MyEntityData myData = cache.FindById<![CDATA[<]]>MyEntityData<![CDATA[>]]>(data.Id);
    ///     
    /// </code>
    /// </example>
    public interface IEntityCache : IObjectDataCache
    {
        /// <summary>
        /// Finds the <see cref="IEntityData"/> instance in the cache.
        /// </summary>
        /// <param name="entityId"><see cref="IEntityData"/> Id</param>
        /// <returns>The <see cref="IEntityData"/> instance in the cache having Id equal to <paramref name="entityId"/> if found or returns <see langword="null" /></returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="entityId"/> is <see langword="null" /> or empty.</exception>
        IEntityData FindById(string entityId);
    }

    /// <summary>
    /// Saves and retreive <see cref="IEntityData"/> instance to/from cache
    /// </summary>
    /// <remarks>
    /// The object will be cached using <see cref="IEntityData"/> concrete type class name and Id property as cache key. So the <see cref="IEntityData"/> Id property must be unique for each concrete class type.
    /// </remarks>
    /// <example>
    /// Add/Find
    /// <code>
    ///     IEntityData data = MyService.GetEntity();
    ///     IEntityDataCache cache = CacheFactory.GetCache();
    ///     
    ///     cache.Add(data);
    ///     IEntityData cacheData = cache.FindById(data.GetType().Name, data.Id);
    ///     MyEntityData myData = cache.FindById<![CDATA[<]]>MyEntityData<![CDATA[>]]>(data.Id);
    ///     
    /// </code>
    /// </example>
    /// <typeparam name="T"><see cref="IEntityData">Entity</see> data concrete class type to cache.</typeparam>
    public interface IEntityCache<T> : IObjectDataCache<T>, IEntityCache
        where T : IEntityData
    {
        /// <summary>
        /// Finds the <see cref="IEntityData"/> instance in the cache.
        /// </summary>
        /// <param name="entityId"><see cref="IEntityData"/> Id</param>
        /// <returns>The <see cref="IEntityData"/> instance in the cache having Id equal to <paramref name="entityId"/> if found or returns <see langword="null" /></returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="entityId"/> is <see langword="null" /> or empty.</exception>
        new T FindById(string entityId);
    }

}
